#include "protocol.hpp"
#include "socket.hpp"
#include "inetaddr.hpp"
#include <memory>
int main(int agrc, char *argv[])
{
    if (agrc != 3)
    {
        std::cout << "err usage : " << argv[0] << " server_ip server_port" << std::endl;
        exit(1);
    }
    std::string ip = argv[1];
    int port = std::stoi(argv[2]);
    InetAddr server(ip, port);
    // 创建套接字
    std::shared_ptr<Socket> sock = std::make_shared<TcpSocket>();
    sock->CreateTcpClientSocket();
    // 发送连接请求
    sock->ConnectOrDie(server);
    // 创建协议对象
    std::unique_ptr<Protocol> pro = std::make_unique<Protocol>();
    std::string buffer; // 接受缓冲区
    while (true)
    {
        // 1. 获取数据
        int x, y;
        char oper;
        std::cout << "Please enter x :";
        std::cin >> x;
        std::cout << "Please enter y :";
        std::cin >> y;
        std::cout << "Please enter oper :";
        std::cin >> oper;
        // 2. 构建请求 -> 结构化数据 -> 序列化数据 -> 添加协议报头的数据
        std::string send_massage = pro->BuildComData(x, y, oper);
        // 3. 发送请求
        sock->Send(send_massage);
        Responce res;
        if (pro->GetResponce(sock, buffer, &res))
            res.Show();
    }
    return 0;
}